package com.tiger.sendmessage.caspOpeapi;

import jakarta.annotation.PostConstruct;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
public class ExecService {
    private final Openapi openapi;
    private final SendMsg sendMsg;


    public ExecService(Openapi openapi, SendMsg sendMsg) {
        this.openapi = openapi;
        this.sendMsg = sendMsg;
    }

    //初始化openapi的token
    @PostConstruct
    public void init() {
        openapi.getAccessToken();
    }

    // 每小时执行更新一次token
    @Scheduled(cron = "0 0 * * * ?")
    public void executeTask() {
        openapi.getAccessToken();
    }

    // 每10分钟执行消息发送
    //@Scheduled(fixedRate = 60000)
    //@Scheduled(cron = "0 0/10 * * * ?")
    @Scheduled(cron = "0 */5 * * * ?")
    public void executeSendMsg() {
        sendMsg.sendMsg();
    }


}
